<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 *
 *
 * @package     ceo
 * @subpackage  models
 * @category    models
 * @author      ydd team, wu
 * @copyright   copyright (c) 2012, yaoduoduo, Inc.
 * @filesource
 */
class Demand_temporary_model extends Base_model {
    protected $_table_name = 'demand_temporary';
    protected $_key_name = 'demand_id';
	
	function get_demand_info($id) {
		if(!empty($id))
			$where[$this->_key_name]=$id;
		$user_purview=check_broker_is_visible();
		if(!$user_purview){
			$this->set_or_like('front_man,broker',$this->login_lib->users_name());
		}
		$where['dtime']=0;
		return $this->fetch(NULL, $where,NULL,'row');
	}


	
	function update_demand($data,$id) {
		$where[]=array('demand_id'=>$id);
		return $this->update($data, $where);
	}

	function add_demand($data) {		
		$data['shop_point_id']=$this->login_lib->shop_point_id();
		$data['users_id']=$this->login_lib->users_id();
		$data['ctime']=time();
		return $this->insert ( $data );
	}
	function delete_user_demand($id){
		$this->db->delete($this->_table_name, array('users_id' => $id)); 
	}

	function delete_demand($id){
		$this->db->delete($this->_table_name, array('demand_id' => $id)); 
	}
	function del_demand($data) {
		$where[]=array('demand_id'=>$data['id']);
		$value=array('dtime'=>time());
		return $this->update($value, $where);
	}
	
}